import { getLocalStorage, setLocalStorage } from './utils';
export default {
	install(wf) {
		const loginModule = {
			login() {
				return new Promise((resolve, reject) => {
					let loginInfo = getLocalStorage('wf-login-info') || {};
					const { telephone } = loginInfo;
					if (
						telephone &&
						typeof telephone === 'string' &&
						telephone.length === 11
					) {
						resolve({
							...loginInfo,
							isLogin: true,
							telephone,
						});
					}

					resolve({
						...loginInfo,
						isLogin: false,
						telephone: null,
					});
				});
			},

			updateLoginInfo(info) {
				if (info) {
					setLocalStorage('wf-login-info', info);
				}
			},
		};
		wf.addModule('login', loginModule);
	},
};
